import { ModalForm, ProFormText } from '@ant-design/pro-components';
import { useModel } from '@umijs/max';
import { Form, message } from 'antd';

const waitTime = (time: number = 100) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(true);
    }, time);
  });
};

export default ({ open, onclose }: any) => {
  const { initialState } = useModel('@@initialState');

  const { info } = initialState || {};

  console.log('当前登录信息', info);

  const [form] = Form.useForm<any>();
  return (
    <ModalForm
      open={open}
      title="修改密码"
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => {
          onclose?.();
        },
      }}
      width={600}
      onFinish={async (values) => {
        await waitTime(2000);
        console.log(values.name);
        message.success('接口暂未支持');
        return true;
      }}
    >
      <ProFormText
        name="project"
        disabled
        label="账号"
        initialValue={info?.count}
      />

      <ProFormText.Password
        name="oldPsw"
        label="登录原密码"
        rules={[{ required: true }]}
      ></ProFormText.Password>

      <ProFormText.Password
        name="newPsw"
        label="输入新密码"
        rules={[{ required: true }]}
      ></ProFormText.Password>

      <ProFormText.Password
        name="newPsw2"
        label="确认新密码"
        rules={[
          {
            required: true,
            validator(rule, value, callback) {
              if (value !== form.getFieldValue('newPsw')) {
                callback('两次输入的密码不一致!');
              } else {
                callback();
              }
            },
          },
        ]}
      ></ProFormText.Password>
    </ModalForm>
  );
};
